﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using BuildingTomorow;

namespace Testing_components
{
    /// <summary>
    /// Interaction logic for TestControl.xaml
    /// </summary>
    public partial class TestControl : UserControl
    {

        ObservableCollection<PresentableGroup> sensors = new ObservableCollection<PresentableGroup>();

        public TestControl()
        {
            InitializeComponent();
            try
            {
                foreach (var item in  DataAccess.GetInstance().GetGroups())
                {
                    sensors.Add(new PresentableGroup(item));
                }
                

            }
            catch
            {

            }
            //sensors.Add(new Sensor { ID = 1, Description = "Bla", Group = "Wall 1", IconPath = "/Testing%20components;component/Images/cloudy.png", Name = "TP 1000", PresentableValue = "18C", Status = true, Type = "Temperarure", Value = 18, X = 2.2, Y = 3.1, Z = 1 });
            //sensors.Add(new Sensor { ID = 2, Description = "Bla2", Group = "Wall 1", IconPath = "/Testing%20components;component/Images/light-snow.png", Name = "TP 1001", PresentableValue = "18.7C", Status = true, Type = "Temperarure", Value = 18, X = 2.2, Y = 3.1, Z = 1 });
            //sensors.Add(new Sensor { ID = 3, Description = "Bla3", Group = "Wall 1", IconPath = "/Testing%20components;component/Images/light-snow.png", Name = "TP 1002", PresentableValue = "19C", Status = true, Type = "Temperarure", Value = 18, X = 2.2, Y = 3.1, Z = 1 });
            //sensors.Add(new Sensor { ID = 4, Description = "Bla4", Group = "Wall 2", IconPath = "/Testing%20components;component/Images/heavy-rain.png", Name = "TP 1003", PresentableValue = "2.6Pn", Status = true, Type = "Humidity", Value = 18, X = 2.2, Y = 3.1, Z = 1 });
            //sensors.Add(new Sensor { ID = 5, Description = "Bla5", Group = "Wall 2", IconPath = "/Testing%20components;component/Images/storm.png", Name = "TP 1004", PresentableValue = "60%", Status = false, Type = "Air Quality", Value = 18, X = 2.2, Y = 3.1, Z = 1 });
            //sensors.Add(new Sensor { ID = 6, Description = "Bla6", Group = "Wall 2", IconPath = "/Testing%20components;component/Images/sunny.png", Name = "TP 1005", PresentableValue = "5PSI", Status = true, Type = "Presure", Value = 18, X = 2.2, Y = 3.1, Z = 1 });
            radTreeView1.DataContext = sensors;
        }


        private void checkboxGroupClicked_Click(object sender, RoutedEventArgs e)
        {
            CheckBox GroupCheckbox = (CheckBox)sender;
            PresentableGroup group = GroupCheckbox.DataContext as PresentableGroup;
            foreach (var item in group.Sensors.Where(x => x.Status == true))
            {
                bool tmp = (bool)GroupCheckbox.IsChecked;
                item.IsSensorSelected = tmp;
            }
        }
    }
}
